//
//  InfoCell.m
//  Mango
//
//  Created by lanou3g on 16/5/9.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "InfoCell.h"

@interface InfoCell ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *coverImageView;
@end

@implementation InfoCell

static CGFloat height = 0;
- (void)setModel:(InfoModel *)model {
    if (_model != model) {
        _model = model;
    }
    
    NSString *urlStr = [model.pic componentsSeparatedByString:@"!"][0];
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:urlStr]];
    _titleLabel.text = model.title;
    
    //计算label的尺寸
    NSDictionary *attriDict = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGRect rect = [_titleLabel.text boundingRectWithSize:CGSizeMake(self.titleLabel.width, MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin attributes:attriDict context:nil];
    height = 8 + self.iconView.height + 8 + rect.size.height + 8;
    
}

- (UIImageView *)iconView {
    if (_coverImageView == nil) {
        _coverImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 8, ScreenSizeW, ScreenSizeW * 562 / 750)];
        [self.contentView addSubview: _coverImageView];
    }
    return  _coverImageView;
}



+ (CGFloat)heightForHeadlineModelCell {
    return  height;
}


#pragma mark 切换至日间模式
-(void)updateToDaySkinMode {
    self.titleLabel.textColor = [UIColor blackColor];
    self.contentView.backgroundColor = [UIColor whiteColor];
}

#pragma mark 切换至夜间模式
-(void)updateToNightSkinMode {
    self.titleLabel.textColor = [UIColor grayColor];
    self.contentView.backgroundColor = [UIColor colorWithRed:42/255.0 green:39/255.0 blue:43/255.0 alpha:1.0];
}


- (void)awakeFromNib {
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
